library(tidyverse)

# mpg ------
mpg <- mpg

ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  # geom_point(aes(color = class))
  # geom_point(aes(alpha = class))
  # geom_point(aes(shape = class))
  facet_grid(drv ~ cyl)

ggplot(data = mpg, aes(x = displ, y = hwy)) +
  geom_point(aes(color = drv)) +
  geom_smooth(mapping = aes(linetype = drv, color = drv))

ggplot(data = mpg, mapping = aes(x = displ, y = hwy)) +
  geom_point(mapping = aes(color = class)) +
  geom_smooth(data = filter(mpg, class == "subcompact"), se = FALSE)

ggplot(data = mpg, mapping = aes(x = class, y = hwy)) +
  geom_boxplot(aes(color = class))

ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  geom_smooth(color = "blue", se = FALSE)

ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  geom_smooth(data = filter(mpg, drv == "f"), se = FALSE, color = "blue") +
  geom_smooth(data = filter(mpg, drv == "r"), se = FALSE, color = "blue") +
  geom_smooth(data = filter(mpg, drv == "4"), se = FALSE, color = "blue")

ggplot(mpg, aes(displ, hwy)) +
  geom_point(aes(color = drv)) +
  geom_smooth(aes(color = drv), se = FALSE)

ggplot(mpg, aes(displ, hwy)) +
  geom_point(aes(color = drv)) +
  geom_smooth(se = FALSE)

ggplot(mpg, aes(displ, hwy)) +
  geom_point(aes(color = drv)) +
  geom_smooth(aes(linetype = drv), se = FALSE)

ggplot(mpg, aes(displ, hwy)) +
  geom_point(aes(fill = drv, stroke = 2), color = "#ffffff", shape = 21) +
  coord_polar()


# diamonds ------
diamonds <- diamonds

ggplot(diamonds) +
  geom_bar(aes(cut))

ggplot(data = diamonds) +
  geom_bar(mapping = aes(x = cut, y = stat(prop), group = 1))

ggplot(data = diamonds) +
  geom_bar(mapping = aes(x = cut, y = stat(prop), group = 2, fill = clarity)) +
  facet_wrap(~ color, nrow = 4)

nz <- map_data("nz")

ggplot(nz, aes(long, lat, group = group)) +
  geom_polygon(fill = "white", colour = "black")

ggplot(nz, aes(long, lat, group = group)) +
  geom_polygon(fill = "white", colour = "black") +
  coord_quickmap()

nz

bar <- ggplot(data = diamonds) +
  geom_bar(
    mapping = aes(x = cut, fill = cut),
    show.legend = FALSE,
    width = 1
  ) +
  theme(aspect.ratio = 1) +
  labs(x = NULL, y = NULL)

bar + coord_flip()
bar + coord_polar()

ggplot(data = mpg, mapping = aes(x = cty, y = hwy)) +
  geom_point() +
  geom_abline() +
  coord_fixed()
